<?php 
	Class activity extends CI_Controller{
		public function __construct(){
			parent::__construct();
			$this->load->model('model_activity');	
		}	
		
		public function index(){
			$provide='';
			if(isset($_GET['provide'])) $provide=$_GET['provide'];
			$name='';
			if(isset($_GET['name'])) $name=$_GET['name'];
			$data['data']=$this->model_activity->getallbyprovide_name($provide,$name);
			
			$data['template']='activity/activity';
			$this->load->view('layout',$data);	
		}
		
		public function edit(){
			if(isset($_GET['id'])){
				$data['detail']	=$this->model_activity->getdata(intval($_GET['id']));				
			}else $data['detail']=NULL;	
			
			$data['template']='activity/activity_edit';
			$this->load->view('layout',$data);	
		}
		
		public function insert(){
			$data['name']=$_POST['name'];			
			$data['address']=$_POST['address'];
			$data['promotion']=$_POST['promotion'];
			$data['category']=$_POST['category'];	
			$data['description']=$_POST['description'];	
			$data['destination']=$_POST['destination'];	
			$data['provide']=$_POST['provide'];
			if($_FILES['fuavatar']['name'] != NULL){
				$config['upload_path'] = './uploads/activity';
				$config['allowed_types'] = '*';
				$config['max_size']	= '3000';
				$config['max_width']  = '2704';
				$config['max_height']  = '2700';
				$this->load->library('upload',$config);
				if(!$this->upload->do_upload("fuavatar")){
					header('Location: '.base_url().'admin/activity/index');
					return FALSE;
				}else{
					$dataimg = $this->upload->data();
					$data['avatar'] = $dataimg['file_name'];
				}
			}
			$data['overview']=$_POST['overview'];
			$data['policy']=$_POST['policy'];		
			$data['typeofactivity']=$_POST['typeofactivity'];
			$data['recommendations']=$_POST['recommendations'];				
			$data['whouse']=$_POST['whouse'];
			$data['detail']=$_POST['detail'];
			$data['status']=$_POST['status'];
			
			$this->model_activity->add($data);
			header('Location: '.base_url().'/admin/activity/index');
		}
		
		public function update(){
			if(isset($_GET["id"])){
				$data['name']=$_POST['name'];			
				$data['address']=$_POST['address'];
				$data['promotion']=$_POST['promotion'];
				$data['category']=$_POST['category'];	
				$data['description']=$_POST['description'];	
				$data['destination']=$_POST['destination'];	
				$data['provide']=$_POST['provide'];	
				if($_FILES['fuavatar']['name'] != NULL){
					$config['upload_path'] = './uploads/activity';
					$config['allowed_types'] = '*';
					$config['max_size']	= '3000';
					$config['max_width']  = '2704';
					$config['max_height']  = '2700';
					$this->load->library('upload',$config);
					if(!$this->upload->do_upload("fuavatar")){
						header('Location: '.base_url().'admin/activity/index');
						return FALSE;
					}else{
						$dataimg = $this->upload->data();
						$data['avatar'] = $dataimg['file_name'];
					}
				}
				$data['overview']=$_POST['overview'];
				$data['policy']=$_POST['policy'];
				$data['whouse']=$_POST['whouse'];
				$data['detail']=$_POST['detail'];				
				$data['typeofactivity']=$_POST['typeofactivity'];
				$data['recommendations']=$_POST['recommendations'];
				$data['status']=$_POST['status'];
				
				$this->model_activity->update($data,intval($_GET['id']));
				header('Location: '.base_url().'/admin/activity/index');
			}	
		}
		
		public function delete(){
			if(isset($_GET["id"])){
				$this->model_activity->del(intval($_GET['id']));	
				header('Location: '.base_url().'/admin/activity/index');
			}	
		}
		
		public function changestatus(){			
			if(isset($_GET["id"])){		
				$data=$this->model_activity->getdata(intval($_GET["id"]));								
				if(count($data)>0){
					if(isset($_GET["status"])){
						$data['status']=intval($_GET['status']);
						$this->model_activity->update($data,intval($_GET["id"]));
						header('Location: '.base_url().'/admin/activity/index');
					}
				}
			}
		}
	}
?>